<template>
  <div class="bond">
    <a-row :gutter="gutter">
      <a-col>
        <a-button type="primary" @click="backList">返回</a-button>
      </a-col>
    </a-row>
    <div class="top-settle">
      <p>保证金余额：<span>{{deposit}}</span></p>
      <p>提现中：<span>{{deposit_withdrawing}}</span></p>
      <p>已提现：<span>{{deposit_withdraw}}</span></p>
    </div>
    <a-form class="search-form" :form="form">
      <a-row :gutter="gutter">
        <a-col :lg="8" :xl="5" :xxl="3">
          <a-form-item label="类型：">
            <a-select style="width: 80%" v-model="searchParams.type">
              <a-select-option
                v-for="item in typeList"
                :key="item.value"
                :value="item.value"
              >{{item.label}}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :lg="8" :xl="5" :xxl="3">
          <a-form-item label="处理状态：">
            <a-select style="width: 80%" v-model="searchParams.status">
              <a-select-option
                v-for="item in handleList"
                :key="item.value"
                :value="item.value"
              >{{item.label}}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :lg="16" :xl="8" :xxl="6">
          <a-form-item label="时间">
            <date :value="time" @change="dateChange"/>
          </a-form-item>
        </a-col>
        <a-col :lg="10" :xl="8" :xxl="4">
          <a-form-item label="流水号：">
            <a-input style="width: 100%" v-model.trim="searchParams.no" placeholder="请输入查询条件"/>
          </a-form-item>
        </a-col>
        <a-col :lg="8" :xl="8" :xxl="5">
          <div class="top-btns">
            <a-button @click="searrchList" type="primary" html-type="submit">查询</a-button>
            <a-button @click="resetcondition">重置</a-button>
          </div>
        </a-col>
      </a-row>
    </a-form>
    <a-table
      :columns="columns"
      rowKey="id"
      :dataSource="columnsData"
      :pagination="pagination"
      :loading="loading"
    ></a-table>
    <pagination
      :total="total"
      @loadDataList="pageInit"
      ref="pageBand"
    />
  </div>
</template>

<script>
// 保证金信息
import { partnerDeposit } from '../../../store/providerApi'
export default {
  data() {
    return {
      total: 0,
      form: this.$form.createForm(this),
      gutter: {
        xs: 8,
        sm: 16,
        md: 16,
        lg: 24,
        xl: 24,
        xxl: 10
      },
      deposit: '',
      deposit_withdraw: '',
      deposit_withdrawing: '',
      pagination: false,
      typeList: [
        {
          label: '全部',
          value: 0
        },
        {
          label: '充值',
          value: 1
        },
        {
          label: '提现',
          value: 2
        }
      ],
      // 0 全部 1 未处理 2成功 3 失败
      handleList: [
        {
          label: '全部',
          value: 0
        },
        {
          label: '未处理',
          value: 1
        },
        {
          label: '成功',
          value: 2
        },
        {
          label: '失败',
          value: 3
        }
      ],
      time: [],
      searchParams: {
        type: 0,
        no: '',
        status: 0,
        start_time: 0,
        end_item: 0
      },
      loading: false,
      columns: [
        {
          title: '序号',
          dataIndex: 'index'
        },
        {
          title: '流水号',
          dataIndex: 'order_no'
        },
        {
          title: '金额（元）',
          dataIndex: 'amount'
        },
        {
          title: '类型',
          dataIndex: 'type',
          customRender(type) {
            if (type == 1) {
              return '充值'
            } else if (type == 2) {
              return '提现'
            }
          }
        },
        {
          title: '处理状态',
          dataIndex: 'status',
          customRender(status) {
            if (status == 0) {
              return '未处理'
            } else if (status == 1) {
              return '成功'
            } else if (status == 2) {
              return '失败'
            }
          }
        },
        {
          title: '创建时间',
          dataIndex: 'created_at'
        },
        {
          title: '完成时间',
          dataIndex: 'done_at'
        }
      ],
      columnsData: []
    }
  },
  // mounted () {
  //   this.pageInit()
  // },
  methods: {
    pageInit (info) {
      partnerDeposit({
        id: this.$route.query.id,
        type: this.searchParams.type,// 0 全部 1 充值 2提现
        status: this.searchParams.status,
        start_time: this.searchParams.start_time,
        end_time: this.searchParams.end_time,
        order_no: this.searchParams.no,
        page: info.page,
        num: info.pageSize
      }).then(res => {
        var array = res.data.list
        for (let i = 0; i < array.length; i++) {
          array[i]['index'] = (info.page - 1) * info.pageSize + (i + 1)
        }
        this.columnsData = array
        this.deposit = res.data.deposit
        this.deposit_withdrawing = res.data.deposit_withdrawing
        this.deposit_withdraw = res.data.deposit_withdraw
        // 分页器总页数
        this.total = res.data.total_num
      })
    },
    // 时间改变
    dateChange({ date, start_time, end_time }) {
      this.time = date
      this.searchParams.start_time = start_time
      this.searchParams.end_time = end_time
    },
    // 重置
    resetcondition() {
      this.time = []
      this.searchParams = {
        type: 0,
        no: '',
        status: 0,
        start_time: 0,
        end_item: 0
      }
      this.$refs.pageBand.getData()
    },
    // 搜索
    searrchList() {
      this.$refs.pageBand.getData()
    },
    backList() {
      this.$router.push('/menu/provider/list')
    }
  }
}
</script>

<style lang="scss" scoped>
.bond {
  margin-top: 15px;
  .top-settle {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    border: 1px solid #eee;
    margin-top: 12px;
    margin-bottom: 12px;
    p{
      margin-bottom: 0;
      padding-left: 20px;
    }
  }
}
</style>